/*
board-games:	An educational framework for board games programming.
    Copyright (C) 2008  Daniel Gutson, FuDePAN
    
    This file is part of board-games.

    board-games is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    board-games is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
*/

#include <stddef.h>
#include "common_sdk/board.h"

#if 0

class PlayerAPI
{
public:
//    void load_player(const char* objname) throw(EPlayerNotFound);
//    template<class FuncType> FuncType get_player_function(const char* funcname) throw(EFunctionNotFound);
    void abandone_game();
    void invalid_player_action();
};

class ShMem
{
public:
    ShMem(SHMEM_ID id, size_t size);
    size_t get_size() const;
    template <class T> T read(size_t pos) const;
    template <class T> void write(size_t pos, T value);
};

#endif

class SharedBoard;

struct PlayerAPI
{

    virtual void send_message_to_referee(const void* msgdata, size_t size) = 0;
    virtual void receive_message_from_referee(void*& msgdata, size_t& size) = 0;
    virtual void connect_board_with_referee(SharedBoard& board) = 0;
    virtual size_t get_srand() const = 0;
    
    template <class T>
    void receive_message_from_referee(T& t)
    {
        void* received_data;
        size_t received_size;
        receive_message_from_referee(received_data, received_size);
        if (received_size == sizeof(T))
            t = *reinterpret_cast<T*>(received_data);
        else
            throw "Invalid message";
    }
    
    template <class T>
    void send_message_to_referee(const T& t)
    {
        send_message_to_referee(&t, sizeof(T));
    }
//    virtual Board* get_board() = 0;
};

struct Player
{
    //virtual void init(const char* playerobj, const ShMem& brd, PlayerID player) = 0;
    //virtual void receive_message(int message, ShMem& mem) = 0;
    virtual void play() = 0;
    
    virtual ~Player(){}
};

extern "C" {
extern Player* create_player(PlayerAPI* api);
}
